package com.tzbank.wisdom.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.tzbank.esb.util.EsbConsumerUtil;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultCode;
import com.tzbank.utils.ResultUtil;
import com.tzbank.wisdom.service.CardBinInfoService;
import com.tzbank.wisdom.utils.RequestMap;
import com.tzbank.wisdom.utils.TransCodeEnum;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;

@Service
@Slf4j
public class CardBinInfoServiceImpl implements CardBinInfoService {

	@Override
	public Map<String, Object> getCardBinInfo(Map<String, String> reqBody) {
		String payeeAcctNo = reqBody.get("payeeAcctNo");
		log.info("请求参数【{}】", JSONObject.fromObject(reqBody).toString());
		Map<String, Object> inputMap = new HashMap<String, Object>();
		Map<String, Object> reqSysHead = RequestMap.getReqSysHead(TransCodeEnum.TRANS_CARDBIN.getServiceCode(), TransCodeEnum.TRANS_CARDBIN.getServiceSence(), "", "", "");
		// 调用核心计价因子报文头入参
		inputMap.put("sysHead", reqSysHead);
		// 报文体
		inputMap.put("payeeAcctNo", payeeAcctNo);// 收款人账号6226220136277802
		inputMap.put("payerAcctNo", reqBody.get("payerAcctNo"));// 付款人账号
		inputMap.put("logonMode", "1");// 登录类型

		Map<String, Object> result = EsbConsumerUtil.clientRequestNoHead(inputMap);
		log.info("响应【{}】", JSONObject.fromObject(result));
		if (!CodeUtil.CODE_200.getCode().equals(result.get("code"))) {
			return ResultUtil.resultMap(result.get("msg").toString(), ResultCode.RESUTL_CODE_FAILURE.code(), result.get("data"));
		}
		return ResultUtil.resultMap("卡bin信息查询成功", ResultCode.RESULT_CODE_SUCCESS.code(), result.get("data"));
	}

}
